package com.github.binarywang.demo.wechat.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.binarywang.demo.wechat.model.ResponseResult;
import com.github.binarywang.demo.wechat.model.Type;
import com.github.binarywang.demo.wechat.service.WxTypeService;
import com.github.binarywang.demo.wechat.utils.JsonUtils;

@RequestMapping({ "wechat/type" })
@RestController
public class WxTypeController {
	@Autowired
	private WxTypeService wxTypeService;

	@GetMapping({ "insert" })
	public int insert(Type type) {
		return this.wxTypeService.insert(type);
	}

	@GetMapping({ "list" })
	public String list() {
		return JsonUtils.toJson(this.wxTypeService.list());
	}
	
	@GetMapping({ "list_" })
	public ResponseResult<Type> list_() {
		ResponseResult<Type> result = new ResponseResult<Type>();
		List<Type> typeList = this.wxTypeService.list();
		result.setCode(0);
		result.setCount(typeList.size());
		result.setData(typeList);
		return result;
	}

	@GetMapping({ "findById" })
	public String list(Integer id) {
		return JsonUtils.toJson(this.wxTypeService.findById(id));
	}

	@GetMapping({ "delete" })
	public int delete(Integer id) {
		return this.wxTypeService.delete(id);
	}

	@GetMapping({ "edit" })
	public int edit(Type type) {
		return this.wxTypeService.edit(type);
	}
}
